package si.yun.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import si.yun.dao.OpeHomeDao;
import si.yun.entity.ProductTable;
import si.yun.entity.SyProduct;
import si.yun.service.OpeService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName OpeHomeServiceImpl
 * @description:
 * @Author 李军瑶
 * @Date 2021/7/29 16:19
 **/
@Service
public class OpeHomeServiceImpl implements OpeService {

    @Autowired
    private OpeHomeDao dao;

    /**
    * @Description 统计昨日订单数和昨日销售额度
    * @return java.lang.Integer
    * @Date 19:34 2021/7/29
    */
    @Override
    public List<Map<String,Object>> getYesterdayOrder() {
        List<Map<String,Object>> yesterdayOrder = dao.getYesterdayOrder();
        return yesterdayOrder;
    }

    /**
     * @Description 统计全部订单数和销售总额
     * @return java.lang.Integer
     * @Date 16:20 2021/7/29
     */
    @Override
    public List<Map<String,Object>> getAllOrders() {
        List<Map<String,Object>> allOrders = dao.getAllOrders();
        return allOrders;
    }

    /**
    * @Description 统计待审核课程
    * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
    * @Date 8:59 2021/7/30
    */
    @Override
    public List<Map<String, Object>> getAuditCourses(Integer AuditCourses) {
        List<Map<String, Object>> auditCourses = dao.getAuditCourses(AuditCourses);
        return auditCourses;
    }

    /**
    * @Description 统计待审核商品
    * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
    * @Date 9:58 2021/7/30
    */
    @Override
    public List<Map<String, Object>> getAuditProduct(Integer AuditProduct) {
        List<Map<String, Object>> auditProduct = dao.getAuditProduct(AuditProduct);
        return auditProduct;
    }

    /**
    * @Description 统计时间段内所有订单——统计图
    * @return java.util.List<java.lang.Integer>
    * @Date 9:07 2021/8/2
    */
    @Override
    public List<Integer> getSpecifyDate(String SpecifyDate) {
        String DataTime1=SpecifyDate+" 0:00:00";
        String DataTime2=SpecifyDate+" 3:00:00";
        String DataTime3=SpecifyDate+" 6:00:00";
        String DataTime4=SpecifyDate+" 9:00:00";
        String DataTime5=SpecifyDate+" 12:00:00";
        String DataTime6=SpecifyDate+" 15:00:00";
        String DataTime7=SpecifyDate+" 18:00:00";
        String DataTime8=SpecifyDate+" 21:00:00";
        String DataTime9=SpecifyDate+" 0:00:00";
        //定义list集合添加数据
        List list=new ArrayList();
        list.add(DataTime1);
        list.add(DataTime2);
        list.add(DataTime3);
        list.add(DataTime4);
        list.add(DataTime5);
        list.add(DataTime6);
        list.add(DataTime7);
        list.add(DataTime8);
        list.add(DataTime9);

        List list1 = new ArrayList();
        for(int i = 1; i<list.size(); i++){
            String minDateTime= (String) list.get(i-1);
            String maxDateTime= (String) list.get(i);
            Integer timeOrder = dao.getTimeOrder(minDateTime, maxDateTime);
            list1.add(timeOrder);
        }
        return list1;
    }

    /**
    * @Description 获取两个日期的订单 求百分比
    * @return java.lang.Integer
    * @Date 19:14 2021/8/3
    */
    @Override
    public Integer getOrdersNumber(String yesterday, String today) {
        String DataTime1=yesterday+" 23:59:59";
        String DataTime2=today+" 23:59:59";
        Integer timeOrder = dao.getTimeOrder(DataTime1, DataTime2);
        return timeOrder;
    }
    /**
    * @Description 获取下拉框的分类
    * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
    * @Date 19:18 2021/8/3
    */
    @Override
    public List<Map<String, Object>> getClassifys() {
        List<Map<String, Object>> classifys = dao.getClassifys();
        return classifys;
    }

    @Override
    public List<Map<String,Object>> getZtree(Integer parentId) {
        /*List<Map<String,Object>> ztree = dao.getZtree(parentId);
        return ztree;*/

        /*List<Map<String,Object>> list=new ArrayList<>() ;
        List<Map<String,Object>> maps = dao.getZtree(0) ;
        for (Map<String,Object> map :maps) {
            int id = (int) map.get("id");
            map.put(" open", true);
            List<Map<String, Object>> child = getChildren(id);
            map.put(" children", child);
            list.add(map);
        }
            return list;*/

        List<Map<String,Object>> list=new ArrayList<>() ;
        List<Map<String,Object>> list2=new ArrayList<>() ;
        Map<String, Object> map4=new HashMap<String,Object>();
        map4.put("id",parentId);
        map4.put("pId",0);
        map4.put("title","课程分类");
        int id = (int) map4.get("pId");
        map4.put("open", true);
        List<Map<String, Object>> child = getChildren(id);
        map4.put("children", child);
        list.add(map4);
        return list;

    }
    public List<Map<String,Object>> getChildren(Integer id) {
        //根据父节点获取子节点
        List<Map<String,Object>> children = dao.getZtree(id);
        //三级目录
        if(children!=null) {
            for(Map<String,Object> child:children) {
                int id2 = (int) child.get("id");
                int parentIdssss= (int) child.get("parentId");
                List<Map<String,Object>> children2=getChildren(id2);
                child.put("open", true);
                child.put("children",children2);
            }
        }
        return children;
    }
    //封装获取子节点的方法
   /* public List<Map<String,Object>> getChildren(Integer id) {
        //根据父节点获取子节点
        List<Map<String,Object>> children = dao.getZtree(id);
        //三级目录
        if(children!=null) {
            for(Map<String,Object> child:children) {
                int id2 = (int) child.get("id");
                List<Map<String,Object>> children2=getChildren(id2);
                child.put("children",children2);
            }
        }
        return children;
    }*/
    /**
    * @Description 获取商品列表table表格
    * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
    * @Date 16:36 2021/8/4
    */
    @Override
    public List<Map<String, Object>> getTables(ProductTable protab) {
        List<Map<String, Object>> tables = dao.getTables(protab);
        return tables;
    }
    /**
    * @Description 修改商品信息
    * @return int
    * @Date 17:35 2021/8/6
    */
    @Override
    public int setProduct(ProductTable protab) {
        int product = dao.setProduct(protab);
        return product;
    }
    /**
    * @Description 删除商品信息
    * @return int
    * @Date 14:36 2021/8/10
    */
    @Override
    public int reProduct(Integer productId) {
        int i = dao.reProduct(productId);
        return i;
    }
    /**
    * @Description 审核详情
    * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
    * @Date 19:14 2021/8/10
    */
    @Override
    public List<Map<String, Object>> getAuditDetails(Integer productId, Integer type) {
        List<Map<String, Object>> list = dao.getAuditDetails(productId, type);
        return list;
    }
    /**
    * @Description 商品导入
    * @return int
    * @Date 16:12 2021/8/13
    */
    @Override
    public int addInsimportExcel(List<SyProduct> list) {
        int i = dao.addInsimportExcel(list);
        return i;
    }
    /**
    * @Description 商品操作日志
    * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
    * @Date 10:58 2021/8/15
    */
    @Override
    public List<Map<String, Object>> getOperation(Integer productId) {
        List operation = dao.getOperation(productId);
        return operation;
    }
    /**
    * @Description 商品审核列表
    * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
    * @Date 11:17 2021/8/15
    */
    @Override
    public List<Map<String, Object>> getCommodityAudit(ProductTable protab) {
        List commodityAudit = dao.getCommodityAudit(protab);
        return commodityAudit;
    }
    /**
    * @Description 统计审核状态的商品数量
    * @return int
    * @Date 17:03 2021/8/15
    */
    @Override
    public int getStatisticalAuditStatus(Integer productSate) {
        int status = dao.getStatisticalAuditStatus(productSate);
        return status;
    }

    /**
    * @Description 商品审核弹出层
    * @return int
    * @Date 11:58 2021/8/17
    */
    @Override
    public int setCommodityAudit(Integer productSate, Integer productId,String result,String details,Integer type) {
        //商品审核
        int i = dao.setCommodityAudit(productSate, productId);
        //添加商品审核记录
        int i1 = dao.addAuditLogGing(productId, result, details, type);

        if(i!=0&&i1!=0){
            return i+i1;
        }else{
            return 0;
        }
    }
    /**
    * @Description 商品订单列表
    * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
    * @Date 16:46 2021/8/24
    */
    @Override
    public List<Map<String, Object>> addOrdersGoods(ProductTable protab) {
        List list = dao.addOrdersGoods(protab);
        return list;
    }

    @Override
    public int getOrderNumber(Integer orderType, Integer orderStatus) {
        int orderNumber = dao.getOrderNumber(orderType, orderStatus);
        return orderNumber;
    }
}


